package com.midea.ai.air.ui.more.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.ui.more.MoreSettingAirExpert;
import com.midea.ai.air.ui.more.MoreSettingAirExpertShowTemp;
import com.midea.ai.air.ui.more.adapter.MoreSettingAirExpertAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hww on 2016/4/25.
 * <p/>
 * 空气达人Fragment
 */
public class MoreSettingAirExpertFragment extends BaseFragment {


    private ListView listView;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_moresettingairexpert, container, false);

        init(view);
        return view;
    }

    private void init(View v) {
        listView = (ListView) v.findViewById(R.id.more_setting_air_expert_listView);
        listView.setAdapter(new MoreSettingAirExpertAdapter(getActivity(), getData()));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                air_expert_context aec = listData.get(position);
                int temp = aec.getTemp();
                Intent intent = new Intent(getActivity(), MoreSettingAirExpertShowTemp.class);
                intent.putExtra(MoreSettingAirExpert.POSITION, position);
                intent.putExtra(MoreSettingAirExpert.TEMP, temp);
                startActivity(intent);
            }
        });
    }


    List<air_expert_context> listData;

    private List<air_expert_context> getData() {
        listData = new ArrayList<air_expert_context>();
        for (int i = 0; i < 10; i++) {
            air_expert_context ct = new air_expert_context();
            ct.setTemp(30 - i);
            ct.setTime(0);
            listData.add(ct);
        }
        return listData;
    }


    public class air_expert_context {
        private int temp;//温度
        private int time;//时间(小时)

        public int getTemp() {
            return temp;
        }

        public void setTemp(int temp) {
            this.temp = temp;
        }

        public int getTime() {
            return time;
        }

        public void setTime(int time) {
            this.time = time;
        }
    }

}
